#! /usr/bin/env python
# -*- coding:utf-8 -*-
# Author Jmz
# type用法一
class dog(object):
    def __int__(self):
        pass
    def eat(self):
        print('dog eating...')

dog1 = dog()
dog1.eat()          # dog eating...
print(type(dog1))   # <class '__main__.dog'>
print(dog.__dict__)
# {'__module__': '__main__', '__int__': <function dog.__int__ at 0x00000000021B9950>, 'eat': <function dog.eat at 0x00000000021B99D8>, '__dict__': <attribute '__dict__' of 'dog' objects>, '__weakref__': <attribute '__weakref__' of 'dog' objects>, '__doc__': None}

# type 用法二
def __init__(self):
    pass
def eat(self):
    print("cat eating...")
cat = type('cat',(object,),{"__init__":__init__,"eat":eat})

cat1 = cat()
cat1.eat()          # cat eating...
print(type(cat1))  # <class '__main__.cat'>
print(cat.__dict__)
# {'__init__': <function __init__ at 0x00000000004D1EA0>, 'eat': <function eat at 0x00000000022D9A60>, '__module__': '__main__', '__dict__': <attribute '__dict__' of 'cat' objects>, '__weakref__': <attribute '__weakref__' of 'cat' objects>, '__doc__': None}



# 分析：
#     1、dog 类 与cat类功能基本一致，只是实现方式不同，一个使用了class 定义了类，一个使用了type产生了一个类
#     2、dog类与cat类实例化方式一样，
#     3、产生对象后的调用对象方法一样
#     4、__dict__ 类的内容基本一致

# 总结：
#     class 关键字的底层实现就是做了与type方法一样的事








